Completed
Push — master ( 729a6c...c9d823 )
by Stefan
02:41
created

mocha_test.js ➔ assertH3   A

Complexity

Conditions 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
1
/**
2
 * Test for getting started with Selenium.
3
 */
4
"use strict";
5
6
7
8
const assert = require("assert");
9
const test = require("selenium-webdriver/testing");
10
const webdriver = require("selenium-webdriver");
11
const firefox = require('selenium-webdriver/firefox');
12
const By = webdriver.By;
13
14
let browser;
15
16
17
function goToNavLink(target) {
18
    browser.findElement(By.linkText(target)).then(function(element) {
19
        element.click();
20
    });
21
}
22
23
function matchUrl(target) {
24
    browser.getCurrentUrl().then(function(url) {
25
        assert.ok(url.endsWith("/" + target));
26
    });
27
}
28
29
function assertH3(target) {
30
    browser.findElement(By.css("h3")).then(function(element) {
31
        element.getText().then(function(text) {
32
            assert.equal(text, target);
33
        });
34
    });
35
}
36
37
// Test suite
38
test.describe("Me-page", function() {
39
40
    this.timeout(0);
41
42
    beforeEach(function(done) {
43
        browser = new webdriver.Builder()
44
            .withCapabilities(webdriver.Capabilities.firefox())
45
            .setFirefoxOptions(new firefox.Options().headless())
46
            .forBrowser('firefox')
47
            .build();
48
49
        // browser.get("https://listrom.me/");
50
        browser.get("http://localhost:3000/");
51
        done();
52
    });
53
54
    afterEach(function(done) {
55
        browser.quit();
56
        done();
57
    });
58
59
60
    // Usecase 1
61
    test.it("Test index", function(done) {
62
63
        browser.getTitle().then(function(title) {
64
            assert.equal(title, "My me-page jsramverk");
65
        });
66
67
        done();
68
    });
69
70
71
    // Usecase 2
72
    test.it("Test go to Reports", function(done) {
73
        // try use nav link
74
        goToNavLink("Reports");
75
        goToNavLink("Kmom 1");
76
77
        matchUrl("reports/week/1" );
78
        assertH3("Kmom 1");
79
80
        done();
81
    });
82
83
84
    // Usecase 3
85
    test.it("Test go to Login", function(done) {
86
        goToNavLink("Login");
87
88
        matchUrl("login/");
89
        assertH3("Login");
90
91
        done();
92
    });
93
94
});